/*********************************************************
  RddStruct.h
  SMART -- Symbolic Moment Analysis for Rapid Timing
  06-08-2008
  (c) Guoyong Shi; SJTU
  09-11-2008
  Zhigang Hao; SJTU
  Code Design:
  (1) About the node number: For this specific application of moment
  calculation, a node number is used as an index to locate the 
  moment array; no other meaning is given.
  (2) Because no moments needed for the GND node and the SRC node,
  these two nodes are numbered "-1" (the default node number).
 ******************************************************/

#ifndef RDD_STRUCT_H
#define RDD_STRUCT_H


#include "SmartGlobal.h"

// Define type names to avoid duplicate type names when 
// integrating with other packages.
struct  t_elem;
struct  t_elem_p;

// Circuit node
typedef struct t_node
{
  char  name[NODE_LENGTH]; // node name (given in netlist), orig 100, 10 is ok
  int   number;  // node number (see Code Design above)
  int  visited;  // visited or not
  int  fanout;  // num of fanout branches
  struct t_elem_p *elem_p; // list of elements connected to this node
  struct t_node  *next;  // in a linked list.
  //t_node *next point to the next node in the same hash tray in symboltable
} T_NODE; // "T_" indicates "tree" circuit

// Circuit edge
typedef struct t_elem
{
  char  name[ELEMENT_LENGTH];  // element name (given in netlist)
  //double value[MONTECARLO_SAMPLE+1];
  double value[2]; // store original value and current value
//  int type; // the type of this element (Y/Z/L/C/VC/VS/CC/CS).
//  use tolower(name[0])
  T_NODE *node1;
  T_NODE *node2;   // two nodes connected by the edge
  struct t_elem *next; // in a linked list
} T_ELEM;

// Circuit source
typedef struct t_src
{
  char  name[ELEMENT_LENGTH];  // element name (given in netlist)
  T_NODE *node1;
  T_NODE *node2;   // two nodes connected by the edge
  int type; // 1:DC(1 parameter), 2:AC(2 parameter), 3:PULSE(7 parameter), 4:SIN(6 parameter), 5:EXP(6 parameter)
  double para1;
  double para2;
  double para3;
  double para4;
  double para5;
  double para6;
  double para7;
  struct t_src *next; // in a linked list
} T_SRC;

// A list of T_ELEM pointers
typedef struct t_elem_p
{
  T_ELEM *elem;
  struct t_elem_p *next; // in a linked list
} T_ELEM_P;


// C_Tree node
typedef struct c_node
{
  int  number;  // numbered from 0
  // C_NODE number is equal to the moment index
  int   fanout;  // fanout of this node
  //double Cap;  // saved capacitance Ci
  double SumHigherOrder;  // summed Ci or (Ci*moment[i, j-1])
  double SumLowerOrder;   // summed Ci or (Ci*moment[i, j-2])
  T_ELEM  *elemR;  // points to Ri (will be used when constructing RDD)
  T_ELEM  *elemL;  // points to Li (will be used when constructing RDD)
  T_ELEM  *elemC;  // points to Ci (just for debugging; will be removed)
  struct c_node **child; // list of fanout nodes
} C_NODE;

struct BDD_Node {
  int   index;
  bool  visited:1;

  char  name[RESISTOR_LENGTH]; // name of the resistor
  T_ELEM *elemR;  // points to R element
  T_ELEM *elemL;  // points to L element

  C_NODE   *Then;  // all "Then" edge points to a C_NODE
  BDD_Node  *Else;  // alias "Else"
};

#endif

